<template>
	<view class="operate u-skeleton">
		<u-navbar title="修改操作密码" :background="{
			'backgroundColor':'#fff'
		}" :borderBottom="false" class="u-skeleton-rect"></u-navbar>
		<view class="title">修改密码</view>
		<view class="box-input center">
			<u-message-input :maxlength="6" :value="password" :dot-fill='true' @change='change'></u-message-input>
		</view>
		<view class="box-input input-code">
			<input type="text" placeholder="请输入验证码" v-model="verification_code">
			<text class="txt" @click="getcode" v-if="!time_num">获取验证码</text>
			<text class="txt code" v-else>{{time_num}}s</text>
		</view>
		<u-button class="btn-primary u-skeleton-rect" ripple-bg-color="rgba(0,0,0,.4)" @click="edituser"
			:ripple="true">确定</u-button>
		<u-skeleton :loading="loding" :animation="true" bgColor="#FFF"></u-skeleton>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				//数据加载
				loding: true,
				//手机号
				username:'',
				password:'',
				verification_code:'',
				//倒计时
				time_num: 0,
			}
		},
		onShow() {
			//获取用户数据
			this.getinfo();
		},
		methods: {
			//数据变化
			change(e){
				this.password = e;
			},
			//获取验证码
			getcode() {
				if(!this.username){
					this.$util.taost({
						title:'请输入手机号'
					})
					return false
				}
				this.$http.asyncSendrequest({
					url:'/login/sms_verification_code',
					data:{
						sms_type:2,
						mobile:this.username,
						type:'其他'
					},
					success:res=>{
						if(res.code == 1){
							this.time_num = 60;
							const countdown = setInterval(()=>{
								this.time_num -= 1;
								if(!this.time_num) clearTimeout(countdown);
							},1000)
						} 
						this.$util.taost({
							title:res.msg
						})
					}
				})
			},
			//获取当前个人数据
			getinfo(){
				this.$http.asyncSendrequest({
					url:'/profile/userInfo',
					success:res=>{
						this.username = res.data.username;
						this.loding = false;
					}
				})
			},
			//修改用户信息
			edituser(){
				console.log("数据",this.password)
				if(!this.password){
					this.$util.taost({title:'请输入新的密码'})
					return false;
				}
				if(!this.verification_code){
					this.$util.taost({title:'请输入验证码'})
					return false;
				}
				this.$http.asyncSendrequest({
					url:'/profile/updatePassword',
					data:{
						username:this.username,
						password:this.password,
						verification_code:this.verification_code,
						type:2
					},
					success:res=>{
						this.$util.taost({
							title:res.msg,
							callback:v=>{
								if(res.code == '0') {
									uni.navigateBack({delta:1})
								}
							}
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.operate {
		width: 100%;
		min-height: 100vh;
		background: #FFFFFF;
		padding: 0 30rpx;
		.title{
			font-size: 36rpx;
			font-weight: bold;
			margin: 50rpx 0 30rpx;
		}
		.box-input{
			display: flex;
			align-items: center;
			background: var(--bg-project);
			padding: 20rpx;
			border-radius: 6rpx;
			margin: 30rpx 0;
			input{
				width: calc(100% - 200rpx);
				font-size: 26rpx;
			}
		}
		.center{
			background: none;
			justify-content: center;
		}
		
		.input-code {
			justify-content: space-between;
			.txt {
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #000000;
			}
			.code {
				color: rgba(0, 0, 0, .4);
			}
		}
		
		.btn-primary {
			height: 96rpx;
			background: #292929;
			border-radius: 10rpx;
			text-align: center;
			line-height: 96rpx;
			font-size: 26rpx;
			font-family: PingFang SC;
			color: #FFFFFF;
			margin: 116rpx 0 0;
		}
	}
</style>